package com.teacherevaluation.controller.uitl;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.metadata.Sheet;
import com.alibaba.excel.read.builder.ExcelReaderBuilder;
import com.alibaba.excel.read.builder.ExcelReaderSheetBuilder;
import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.excel.support.ExcelTypeEnum;

import com.teacherevaluation.common.util.ExcelListener;
import com.teacherevaluation.entity.EvaluateBo;
import com.teacherevaluation.entity.LayuiResult;
import com.teacherevaluation.entity.TeacherDB;
import com.teacherevaluation.service.AppraiseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Controller
@RequestMapping("appraise")
public class ExcelController {
    @Autowired
    private AppraiseService appraiseService;

    @PostMapping("/import")
    @ResponseBody
    public LayuiResult<TeacherDB> batchImport(@RequestParam("file") MultipartFile file) throws IOException {
        ExcelReaderBuilder builder = EasyExcel.read(file.getInputStream(), EvaluateBo.class, new ExcelListener());
        ExcelReaderSheetBuilder excelReaderSheetBuilder = builder.sheet();
        excelReaderSheetBuilder.doRead();
        LayuiResult<TeacherDB> result= new LayuiResult<>();
        result.setCode(0);
        return result;
    }
}
